package kr.co.skplanet.commute.dao;

import kr.co.skplanet.commute.domain.Member;
import kr.co.skplanet.commute.repository.hibernate.HibernateGenericRepository;
import kr.co.skplanet.commute.util.StringUtils;

import org.springframework.stereotype.Repository;


@Repository(value = "memberDAO")
public class MemberDAO extends HibernateGenericRepository<Member> {
	public Member findMember(Long id) {
		Member member;
		member = findUniqByObject("id", id);
		
		return member;
	}
	public Member findMember(String email) {
		Member member;
		member = findUniqByObject("email", StringUtils.genSHA256(email));
		
		return member;
	}
	public Member findMember(String email, String passwd) {
		Member member;
		member = findUniqByObject("email", StringUtils.genSHA256(email));
		
		if(member != null) {
			if(!member.getPassword().equals(StringUtils.genSHA256(passwd, member.getSalt(), 1000))) {
				member = null;
			}
		}
		
		return member;
	}
	public Member findMemberByAuthKey(String authkey) {
		Member member;
		member = findUniqByObject("authKey", authkey);
		
		return member;
	}
}
